﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Network
{
    class FinalNeural
    {
        private double[] Weigth;
        private double[] ValueInput;

        public FinalNeural(int _nb)
        {
            Weigth = new double[_nb + 1];
            ValueInput = new  double[_nb] ;        


            for (int i = 0; i < Weigth.Length; i++){
                
            
                Thread.Sleep(30);
                Weigth[i] = Math.Round(Utilitaire.GetRandomNumber(-1, 1), 2);
            }
        }
       

        public  void setValueInput(double[] res)
        {
            for(int i=0;i<res.Length;i++)
            {
                ValueInput[i] = res[i];
            }

        }

        public double getWeigth(int nb)
        {
            return this.Weigth[nb];
        }

        public double getPotential()
        {
            double res = 0;
            for (int i = 0; i<ValueInput.Length;i++)
            {
                res += (ValueInput[i] * Weigth[i]);
            }
            return res;
        }

        public double getOutput()
        {
            double res = 0;
          //  double total = 0;
             for (int i = 0; i<ValueInput.Length;i++)
            {
               //  total += Weigth[i];
                res += (ValueInput[i] * Weigth[i]);
            }
             res += Weigth[Weigth.Length -1];


          //   double test = res / total;

             double output_res = (1.0/(1 + Math.Exp(-res)));

             return output_res;
        }

        public void setWeight(int num, double value)
        {
            this.Weigth[num] = value;

        }

      
    }
}
